package demo.util;

import com.betfair.www.publicapi.types.global.v3.BFEvent;
import com.betfair.www.publicapi.types.global.v3.MarketSummary;

import java.lang.reflect.Field;
import java.text.SimpleDateFormat;

/**
 * Created with IntelliJ IDEA.
 * User: markwilliams
 * Date: 8/18/13
 * Time: 4:01 PM
 * To change this template use File | Settings | File Templates.
 */
public class Util {
    public static String printMarketSummary(MarketSummary m) {
        StringBuilder result = new StringBuilder();
        String newLine = System.getProperty("summary.line.separator");
        if (newLine == null) newLine = "\n";
        SimpleDateFormat df = new SimpleDateFormat();
        df.applyPattern("yyyyMMdd HH:MM:SS");
        df.setCalendar(m.getStartTime());

        result.append(m.getMarketName());
        result.append( " {" );
        result.append(newLine);

        result.append("BetDelay=").append(m.getBetDelay()).append(";");
        result.append("EventParentId=").append(m.getEventParentId()).append(";");
        result.append("EventTypeId=").append(m.getEventTypeId()).append(";");
        result.append("ExchangeId=").append(m.getExchangeId()).append(";");
        result.append("MarketId=").append(m.getMarketId()).append(";");
        result.append("MarketType=").append(m.getMarketType()).append(";");
        result.append("MarketTypeVariant=").append(m.getMarketTypeVariant()).append(";");
        result.append("MenuLevel=").append(m.getMenuLevel()).append(";");
        result.append("NumberOfWinners=").append(m.getNumberOfWinners()).append(";");
        result.append("Orderindex=").append(m.getOrderIndex()).append(";");
        result.append("StartTime=").append(df.format(m.getStartTime().getTime())).append(";");
        result.append("TimeZone=").append(m.getTimezone()).append(";");
        result.append("Venue=").append(m.getVenue()).append(";");

        result.append(newLine);
        result.append("}");

        return result.toString();
    }

    public static String printEvent(BFEvent e) {
        StringBuilder result = new StringBuilder();
        String newLine = System.getProperty("summary.line.separator");
        if (newLine == null) newLine = "\n";
        SimpleDateFormat df = new SimpleDateFormat();
        df.applyPattern("yyyyMMdd HH:MM:SS");
        df.setCalendar(e.getStartTime());

        result.append(e.getEventName());
        result.append( " {" );
        result.append(newLine);

        result.append("EventId=").append(e.getEventId()).append(";");
        result.append("StartTime=").append(df.format(e.getStartTime().getTime())).append(";");
        result.append("TimeZone=").append(e.getTimezone()).append(";");

        result.append(newLine);
        result.append("}");

        return result.toString();
    }
}
